import numpy as np


a = np.arange(1, 6)
b = np.arange(6, 9)

# 完全卷积
print('完全卷积：')
a1 = np.array([0, 0, 1, 2, 3, 4, 5, 0, 0])
b1 = b[::-1]
c1 = []
# 7是计算次数，也是完全卷积的个数，由a.size+b.size-1得到
for i in range(7):
    temp = (a1[i:i+3] * b1).sum() # 3就是b的长度(b.size)
    c1.append(temp)
print(c1)

c = np.convolve(a, b, 'full')
print(c)

# 同维卷积
print('同维卷积：')
a2 = np.array([0, 1, 2, 3, 4, 5, 0])
b2 = b[::-1]
c2 = []
for i in range(5):
    temp = (a2[i:i+3] * b2).sum() 
    c2.append(temp)
print(c2)

c = np.convolve(a, b, 'same')
print(c)

# 有效卷积
print('有效卷积：')
a3 = np.array([1, 2, 3, 4, 5])
b3 = b[::-1]
c3 = []
for i in range(3):
    temp = (a3[i:i+3] * b3).sum() 
    c3.append(temp)
print(c3)

c = np.convolve(a, b, 'valid')
print(c)